import logging

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.drivers.edge import EdgeChromiumDriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager

from config.config import BROWSER_TYPE, HEADLESS, DRIVER_TYPE, EDGE_DRIVER_PATH, CHROME_DRIVER_PATH


def get_driver():
    driver=None
    if BROWSER_TYPE=="edge":
        driver=get_edge_driver()
    elif BROWSER_TYPE=="chrome":
        driver=get_chrome_driver()
    return driver

def get_edge_driver():
    options = webdriver.EdgeOptions()
    options.add_argument("--start-maximized")
    if HEADLESS:
        options.add_argument("--headless")

    if DRIVER_TYPE=="local":
        service=Service(EDGE_DRIVER_PATH)
    else:
        service=Service(EdgeChromiumDriverManager().install())

    driver=webdriver.Edge(options=options,service=service)
    return driver


def get_chrome_driver():
    options = webdriver.ChromeOptions()
    options.add_argument("--start-maximized")
    if HEADLESS:
        options.add_argument("--headless")

    if DRIVER_TYPE=="local":
        service=Service(CHROME_DRIVER_PATH)
    else:
        service=ChromeService(ChromeDriverManager().install())

    driver=webdriver.Chrome(options=options,service=service)
    return driver




